package com.kitchen.ui.dialog.storage
{
	import com.kitchen.AbstractButton;
	import com.kitchen.http.PropProxy;
	import com.kitchen.http.Proxy;
	import com.kitchen.ui.box9grid.BetweenBox;
	import com.kitchen.ui.box9grid.InnerBox;
	import com.kitchen.ui.box9grid.OuterBox;
	import com.kitchen.ui.dialog.AbstractDialog;
	import com.kitchen.ui.dialog.DialogHeader;
	import com.kitchen.ui.dialog.com.CoinItem;
	
	import flash.display.BitmapData;
	import flash.events.Event;
	import flash.events.MouseEvent;

	public class StorageDialog extends AbstractDialog
	{
		private var coinItem:CoinItem;
		private var table:StorageGrid;
		private var propBtn:PropertyButton;
		private var materBtn:GoodsButton;
		private var dstate:int;
		
		public function StorageDialog(main:BitmapData, dialog:BitmapData, shoper:Object=null, shop:Object=null)
		{
			this.dstate =1;
			super(main, dialog, shoper, shop);
		}
		
		override protected function layout(cdata:Object):void{
			this.w = 330;
			this.h = 610;
			var outer:OuterBox = new OuterBox(this.dialogSkin, this.w, this.h-20);
			var between:BetweenBox = new BetweenBox(this.dialogSkin, this.w-20, this.h-110);
			var inner1:InnerBox = new InnerBox(this.dialogSkin, this.w-40, this.h-200);
			outer.x = 0;
			outer.y = 20;
			between.x = 10;
			between.y = 95;
			inner1.x = 20;
			inner1.y = 135;
			this.addChild(outer);
			this.addChild(between);
			this.addChild(inner1);
			var head:StorageHead = new StorageHead(this.mainSkin);
			head.x = (this.w-head.w)/2;
			head.y = 0;
			this.addChild(head);
			this.addCloseButton();
			this.propBtn = new PropertyButton(this.dialogSkin);
			propBtn.name = 'prop';
			propBtn.x = 30;
			propBtn.y = 107;
			propBtn.setChecked(true);
			propBtn.addEventListener(MouseEvent.CLICK, clickHandler);
			this.addChild(propBtn);
			this.materBtn = new GoodsButton(this.dialogSkin);
			materBtn.name = 'mater';
			materBtn.x = 110;
			materBtn.y = 107;
			materBtn.addEventListener(MouseEvent.CLICK, clickHandler);
			this.addChild(materBtn);
			this.table = new StorageGrid(this.mainSkin, this.dialogSkin, 5, 7);
			this.table.x = 38;
			this.table.y = 150;
			this.addChild(this.table);
			this.table.goPage(1);
			var sort:SortButton = new SortButton(this.dialogSkin);
			sort.x = 25;
			sort.y = 545;
			this.addChild(sort);
			var seller:SellerButton = new SellerButton(this.dialogSkin);
			seller.x = 65;
			seller.y = 545;
			this.addChild(seller);
			this.coinItem = new CoinItem(this.dialogSkin, this.mainSkin, this.shoper.nGold);
			coinItem.x = 120;
			coinItem.y = 548;
			this.addChild(coinItem);
		}
		
		private function clickHandler(event:MouseEvent):void{
			var btn:AbstractButton = AbstractButton(event.currentTarget);
			if(btn.name == 'prop'){
				if(this.dstate == 2){
					this.propBtn.setChecked(true);
					this.materBtn.setChecked(false);
					this.dstate = 1;
				}
			}else if(btn.name == 'mater'){
				if(this.dstate == 1){
					this.propBtn.setChecked(false);
					this.materBtn.setChecked(true);
					this.dstate = 2;
				}
			}
		}
	}
}